/*-----------------------------------------------------------------------------
	The contents of this file are subject to the Mozilla Public License
	Version 1.1 (the "License"); you may not use this file except in
	compliance with the License. You may obtain a copy of the License at
	http://www.mozilla.org/MPL/
	
	Software distributed under the License is distributed on an "AS IS"
	basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
	License for the specific language governing rights and limitations
	under the License.
	
	The Original Code is Fever Framework code.
	
	The Initial Developer of the Original Code is Romain Ecarnot.
	Portions created by Initial Developer are Copyright (C) 2006
	the Initial Developer. All Rights Reserved.
	
	Contributor(s):
	
	Unless required by applicable law or agreed to in writing, software
	distributed under the License is distributed on an "AS IS" BASIS,
	WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
	See the License for the specific language governing permissions and
	limitations under the License.
-----------------------------------------------------------------------------*/

import com.bourre.data.collections.Map;

/**
 * Buffer store ( cache system ) folder list content.
 * 
 * <p>This buffer avoid retreiving process when user select folder 
 * to list in FvFileChooser.<br />
 * If the folder is already visited, when user re-visited it, we take folder 
 * informations directly from buffer instead of relaod it using remoting or 
 * other server-side, client-side process.
 * 
 * <p>Buffer is unique for all FvFileChooser in application.
 * 
 * @author Romain Ecarnot
 */
class fvaswing.components.filechooser.mvc.FvFileChooserBuffer
{
	//-------------------------------------------------------------------------
	// Private properties
	//-------------------------------------------------------------------------
	
	private static var _listMap : Map = new Map();	private static var _pathMap : Array = new Array();
	
	
	//-------------------------------------------------------------------------
	// Public API
	//-------------------------------------------------------------------------	
	
	/**
	 * Returns {@code true} if passed-in {@code id} path is stored 
	 * in buffer. Otherwise {@code false}
	 */
	public static function isBuffered( id : String ) : Boolean
	{
		return _listMap.containsKey( id );
	}
	
	/**
	 * Stores passed-in {@code data} in buffer under {@code id} identifier.
	 */
	public static function cache( id : String, data : Array ) : Void
	{
		_listMap.put( id, data );
		_pathMap.push( id );
		_pathMap.sort( Array.CASEINSENSITIVE );
	}
	
	/**
	 * Returns stored list registred with {@code id} identifier.
	 */
	public static function getCacheList( id : String ) : Array
	{
		return _listMap.get( id );
	} 
	
	/**
	 * Returns stored id list.
	 */
	public static function getCachePaths() : Array
	{
		return _pathMap;	
	}
	
	
	//-------------------------------------------------------------------------
	// Private implementation
	//-------------------------------------------------------------------------
	
	/**
	 * Constructor.
	 */
	private function FvFileChooserBuffer() {}
}